package com.restaurant.serviceimpl;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.restaurant.domain.Exceptionalright;
import com.restaurant.service.ExceptionalrightService;

public class ExceptionalrightServiceImpl implements ExceptionalrightService {

   private HibernateTemplate hibernateTemplate;

   @Autowired
   public void setSessionFactory(SessionFactory sessionFactory){
       this.hibernateTemplate = new HibernateTemplate(sessionFactory);
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Exceptionalright addOrModify( Exceptionalright objExceptionalright ) {
       return ( Exceptionalright ) hibernateTemplate.merge( objExceptionalright );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Exceptionalright deleteRecord( Exceptionalright objExceptionalright ) {
       hibernateTemplate.delete( objExceptionalright );
       return objExceptionalright;
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Exceptionalright modifyRecord( Exceptionalright objExceptionalright ) {
       return ( Exceptionalright ) hibernateTemplate.merge( objExceptionalright );
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Exceptionalright> loadAll() {
       return (List<Exceptionalright>)hibernateTemplate.findByNamedQuery( "Exceptionalright.findAll");
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Exceptionalright loadByPrimaryKey( Long primaryKey ) {
       return (Exceptionalright) hibernateTemplate.get( Exceptionalright.class, primaryKey );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Exceptionalright deleteByPrimaryKey( Long primaryKey ) {
       return deleteRecord(loadByPrimaryKey(primaryKey));
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Exceptionalright> loadByHql(String query) {
       return ( List<Exceptionalright> ) hibernateTemplate.find( query );
   }
}